<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr1 = [1, 3, 9, 1, 3]
        let arr2 = [3, 9, 5, 9, 8, 8]

        //去重
        let s1 = new Set(arr1)
        let s2 = new Set(arr2)
        console.log(s1);
        console.log(s2);

        //交集
        let newArr = []

        s1.forEach((item) => {
            s2.forEach((item1) => {
                if (item === item1) {
                    newArr.push(item)
                }

            })
        })
        console.log(newArr);

        //并集
        let newArr1 = [...s1, ...s2]
        console.log(newArr1);

        //差集
        let newArr2 = []
        newArr1.forEach((item) => {
            let flag = true
            newArr.forEach((item1) => {
                if (item == item1) {
                    flag = false
                }
            })
            if (flag) {
                newArr2.push(item)
            }
        })
        console.log(newArr2);
    </script>
</body>

</html>